<?php
/**
* @package YaForms
* @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
* @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
* YaForms! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
* Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
*/

defined( '_VALID_MOS' ) or die( 'Restricted access' );


class HTML_beyaforms {

   function ShowFrontYaForms ( $row, $items, $params, $option ){

      global $mainframe, $my, $gid, $mosConfig_lang, $mosConfig_sitename, $mosConfig_mailfrom, $mosConfig_fromname, $database;
      require( JPATH_BASE.'/administrator/components/com_yaforms/config.yaforms.php' );
	  $config = &Jconfig::getInstance();

      afLoadLib ( 'afforms' );
      afLoadLib ( 'attfiles' );
      afLoadLang();

      $do = mosGetParam( $_POST, 'do' );
      $formtitle = mosGetParam( $_POST, 'formtitle' );
      $formid = mosGetParam( $_REQUEST, 'formid' );

      $joomlauser = mosGetParam( $_POST, 'joomlauser', '' );
      $joomlausername = mosGetParam( $_POST, 'joomlausername', '' );
      $joomlauserip = mosGetParam( $_POST, 'joomlauserip', '' );
	  

      if ( $joomlauser == '' ) $joomlauser = YAF_ANONYMOUS;
      if ( $joomlausername == '' ) $joomlausername = YAF_ANONYMOUS;
      if ( $joomlauserip == '' ) $joomlauserip = YAF_NOIP;

      if( mosGetParam( $_GET, 'af_mod' ) == '1' ){
         $alink = 'index2.php?option=com_yaforms&amp;amp;af_mod=1';
      } else {
         $alink = 'index.php?option=com_yaforms';
      }

      $a_errors = array();
      $a_error_ids = array();
      $attfileerrchk = array();
      $uploadedfile = '';
      $itemname_todb = '';
      $itemdata_todb = '';
      $mail_data = '';
      $html = '';
      
      if(mosGetParam( $_GET, 'option' ) == 'com_yaforms' ){
         $Itemid = mosGetParam( $_GET, 'Itemid' );
         if($Itemid == '' )$Itemid = afGetItemid( $formid );
         if($Itemid == '' )$Itemid = '99999';
      } else {
         $Itemid = afGetItemid( $formid );
         if($Itemid == '' )$Itemid = '99999';
      }

      if( !$row ) {
         mosNotAuth();
         return;
      }

      if ( '1' != mosGetParam( $_GET, 'no_aftitle' ) && $params->get( 'change_page_title' ) == '1' ){
         $mainframe->setPageTitle( $row->titel );
      }
      
      if ( '1' === $afcfg_loadfrontcss && $params->get( 'use_custom_css' ) != '1' ){
         afLoadFECSS();
      }
      
      if ( $params->get( 'use_custom_css' ) === '1' ){
         $htmlh = '<style type="text/css">
                  '.$row->customcss.'
                  </style>';
         $mainframe->addCustomHeadTag( $htmlh );
      }
	  
	  if ($row->metadesc) $mainframe->appendMetaTag( 'description', $row->metadesc );
      if ($row->metakey) $mainframe->appendMetaTag( 'keywords', $row->metakey );

      if ( $params->get( 'show_form_title' ) == '1' ){
         $html .= '<div class="componentheading">
                  '.$row->titel.'
	       </div>';
      }

      $html .= afLoadTitleError(1);

      $html .= '<div id="yaforms-box">';
	  
	  	  if ( $row->seccode == '1' ) {
	  
	  	session_name(mosMainFrame::sessionCookieName());
		session_start();
		$captcha = strval(mosGetParam($_POST, 'captcha', null));
		$captcha_keystring =mosGetParam($_SESSION,'captcha_keystring');
	  
	  }
    
      if ($do == 'send'){

         if ( $row->seccode == '1' ){ //капча джустины
			
			$mosmsg = YAF_CAPTCHA_NOTDEFINED;
			if($captcha_keystring!== $captcha) {
			mosRedirect( sefRelToAbs( $alink.'&amp;formid='.$formid.'&amp;Itemid='.$Itemid ), $mosmsg);
			}
			session_unset();
			session_write_close();
         }

	 //Проверка значений 
	 foreach($items as $item){
	    $data = $_POST['item_'.$item->item_id];
	    
	    if($item->type == '8') continue;
	    if(is_array($data)){
	       $values = split(';', $item->values);
	       $dt = '';
	       foreach($data as $d){
                  $dt .= $values[$d] . ', ';
	       }
	       $data = substr($dt, 0, -2);
	    }
	    $submited_value = trim(stripData($data));
            if( $item->required != '1' ){
               if( $submited_value == '' ){
                  $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' '.YAF_MANDATORY.'</div>';
     	          $a_error_ids[] = $item->item_id;
	          continue;
	       }
	    }
	    if (strrchr( $data, '@') && $row->emailfield != '0' ){
               for( $j=0; $j < count( $data ); $j++ ){
                  $email_copy_to_sender = array();
	          $email_copy_to_sender[$j]=$data;
               }
            }
	    if($item->validation != '0' || $item->validation != ''){//validations start
               if($item->type == '8')continue;
               if($submited_value == '')continue;
               if($item->validation == '1'){ // email
                  if(!validate_email($submited_value)){
                     if($submited_value != ''){
                        $nonemailfix = '-';
                     }else{
                        $nonemailfix = '';
                     }
		     $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.YAF_ONLYEMAILALLOWED.' '.$nonemailfix.' '.$submited_value.'</div>';
		     $a_error_ids[] = $item->item_id;
		  }
	       } else if($item->validation == '2') { // только числа
	          $regExp='[0-9]';
	          if (!ereg($regExp, $submited_value)){
		     $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.YAF_ONLYNUMBERALLOWED.'</div>';
		     $a_error_ids[] = $item->item_id;
	          }
	       } else if($item->validation == '3') { // только текст
	          $regExp='[а-яА-Яa-zA-Z]';
	          if (!ereg($regExp, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.YAF_ONLYTEXTALLOWED.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
               } else if($item->validation == '4') { // текст и числа
	          $regExp='[z0-9а-яА-Яa-zA-Z]';
	          if (!ereg($regExp, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.YAF_ONLYTEXTNUMBERALLOWED.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
               } else if($item->validation == '5') { // decimal
	          $regExp='-?(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?';
	          if (!ereg($regExp, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.YAF_ONLYDECIMALALLOWED.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
               } else if($item->validation == '6') { // дата
                  if ( !YAF_DATEVALIDATION == 'Y-m-d' ){
    				$afcfg_valide_date = '^([2][0]|[1][9])\d{2}\-([0]\d|[1][0-2])\-([0-2]\d|[3][0-1])$';
                  } else {
                     $afcfg_valide_date = '^([2][0]|[1][9])\d{2}\-([0]\d|[1][0-2])\-([0-2]\d|[3][0-1])$';
                  }
                  if (!ereg($afcfg_valide_date, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.YAF_ONLYDATEALLOWED.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
               } else if($item->validation == '7') { // zipcode
	          if (!ereg($afcfg_valide_zipcode, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.YAF_ONLYZIPCODEALLOWED.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
               } else if($item->validation == '8') { // IP
	          $regExp='^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$';
	          if (!ereg($regExp, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.YAF_ONLYIPALLOWED.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
               } else if($item->validation == '9') { // URL
	          $regExp='(((ht|f)tp(s?))\:\/\/)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?';
	          if (!ereg($regExp, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.YAF_ONLYURLALLOWED.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
	       } else if($item->validation == '10') { // Credit Card
	          $regExp='([0-3]*[0-9]+[0-9]+)\.([0-3]*[0-9]+[0-9]+)\.([0-3]*[0-9]+[0-9]+)\.([0-3]*[0-9]+[0-9]+)';
	          if (!ereg($regExp, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.YAF_ONLYCREDITCARDALLOWED.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
               } else if($item->validation == '11') { // custom 1
	          if (!ereg($afcfg_valide_custom1, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.$afcfg_valide_custom1_legend.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
               } else if($item->validation == '12') { // custom 2
	          if (!ereg($afcfg_valide_custom2, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.$afcfg_valide_custom2_legend.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
	       } else if($item->validation == '13') { // custom 3
	          if (!ereg($afcfg_valide_custom3, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.$afcfg_valide_custom3_legend.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
	       } else if($item->validation == '14') { // custom 4
	          if (!ereg($afcfg_valide_custom4, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.$afcfg_valide_custom4_legend.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
	       } else if($item->validation == '15') { // custom 5
	          if (!ereg($afcfg_valide_custom5, $submited_value)) {
	              $a_errors[] = '<div class="yaforms-errorfield">'.$item->name.' - '.$afcfg_valide_custom5_legend.'</div>';
	              $a_error_ids[] = $item->item_id;
	          }
	       }
	    }//конец проверки
            if($item->type == '3' || $item->type == '4') {
	       $a_values = explode(';', $item->values);
	       $submited_value = $_POST['item_'.$item->item_id];
	       if(is_array($submited_value)){
	          $a_tmp = $submited_value;
	          $submited_value = array();
	          foreach($a_tmp as $index){
                     $submited_value[] = $a_values[$index];
		  }
	       } else {
	          $submited_value = $a_values[$submited_value];
	       }
	    }
	    if(is_array($submited_value)){
	       $mail_data[$item->name] = implode(', ', $submited_value);
            } else {
               $mail_data[$item->name] = $submited_value;
            }
            $getitems = $data;
            if (is_array($getitems)){
	       $dt = '';
	       foreach($getitems as $d){
		  $dt .= $d. ', ';
	       }
	       $getitems = substr($dt, 0, -2);
	    }
	    if (isset($item->name)){
	       $itemname_todb .= eregi_replace(';',',',$item->name).';';
	    } else {
               $itemname_todb .= eregi_replace(';',',','-').';';
            }
            $itemdata_todb .= eregi_replace(';',',',$getitems).';';
            
         }//foreach items

         if(count($a_errors) == 0){

            $attachments = null;
            $attachmentstodb = null;
            $meldung = null;
            $meldung2 = null;

            if ( $row->allowatt != '0' ){ // Запускаем загрузку и прикрепление файлов

               $max_size = $row->allowattfilesize; // в кб
               if( $afcfg_att_path != '' && is_dir(JPATH_BASE.$afcfg_att_path) ){
                  $artuplpfad = JPATH_BASE.$afcfg_att_path;
               } else {
                  $artuplpfad = JPATH_BASE.'/images/yaforms/attachedfiles/';
               }
               $attachments = array();
               $attachmentstodb = array();

               $mtypes_key_array = explode(",",$row->allowattfiles);
               $mtypes_allowed = afMimeTypesAllowed();
               $mimetypen_array = array();
			   if ($mimetypen_array){ //если будут проблемы пересмотрим этот момент
               foreach( $mtypes_key_array as $key ){
                  $mimetypen_array[$key] = $mtypes_allowed[$key]['mime'];
               }
				}
               $meldung = '';
               $meldung2 = '';
	       $ok = false;
               $attfilescount = @count($_FILES['attfile']['tmp_name']);

               for( $g = '0'; $g < $attfilescount; $g++ ) {

                  if ( $_FILES['attfile']['error'][$g] == '4' && $_FILES['attfile']['name'][0] == '' && count($_FILES['attfile']['name']) != 1 ){
                     $attfileerrchk[] = '';
					 
                  } elseif ( $_FILES['attfile']['error'][$g] == '4' && $_FILES['attfile']['name'][0] == '' && count($_FILES['attfile']['name']) == 1 ){
				  
                     $meldung .='<div class="yaforms-error">'.YAF_SENTWOUTFILES.'</div>';
                     $attfileerrchk[] = 'error';
					 
                  } else {
				  
                     if ($_FILES['attfile']['size'][$g] == 0){
					 
	                $a_errors[] = '<div class="yaforms-errorwsize">'.YAF_EMPTYORFILESIZESTOP.'<br />( '.YAF_MAX.' '.$max_size.' KBytes )<br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'</div>';
                        $attfileerrchk[] = 'error';
                        $meldung2 .= '<div class="yaforms-error">'.YAF_NOTATTFILES.':<br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'</div>';
						
                     } elseif ($_FILES['attfile']['size'][$g] > ($max_size * 1024)){
					 
	               $a_errors[] = '<div class="yaforms-error">'.YAF_FILESIZESTOP.' <br />(max. '.$max_size.' KBytes)<br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'</div>';
                       $attfileerrchk[] = 'error';
                       $meldung2 .= '<div class="yaforms-error">'.YAF_NOTATTFILES.':<br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'</div>';
					   
                     } elseif (!afMimeTypeIsInArray($_FILES['attfile']['type'][$g], $mimetypen_array)){
                       $chktypealert = '<div class="yaforms-errorwtype">';
					   
	               $chktypealert .= YAF_WRONGTYPE.'<br />*.'.afGetFileExt( $_FILES['attfile']['name'][$g] ).' ('.$_FILES['attfile']['type'][$g].')<br /><br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'<br />';
				   
                       $chktypealert .= '<br />'.YAF_ONLYFILESALLOWED.'<br /><a href="javascript:void(0);" onClick="javascript:if(document.getElementById(\'afallowedfilesspoiler'.$g.'\').style.display != \'\') { document.getElementById(\'afallowedfilesspoiler'.$g.'\').style.display = \'\';this.innerText = \'\'; this.value = \'Hide\'; } else { document.getElementById(\'afallowedfilesspoiler'.$g.'\').style.display = \'none\'; this.innerText = \'\'; this.value = \'Show\'; };">'.YAF_CLICKTOSHOW.'</a><div><div id="afallowedfilesspoiler'.$g.'" style="display: none;"><ul>';
					   
                       foreach ($mtypes_key_array as $key){
	                  $chktypealert .= "\n<li>".$mtypes_allowed[$key]['ext']."</li>";
	               }
	               $chktypealert .= '</ul></div></div></div>';
	               //$chktypealert .= '<div class="yaforms-error">'.YAF_NOTATTFILES.':<br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'</div>';
                       $a_errors[] = $chktypealert;
                       $meldung2 .= '<div class="yaforms-error">'.YAF_NOTATTFILES.':<br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'</div>';
                       $attfileerrchk[] = 'error';
                     } elseif ($_FILES['attfile']['error'][$g] == '0'){
	                $groesse = GetImageSize($_FILES['attfile']['tmp_name'][$g]);
		        if (is_array($groesse)){
		           if ($groesse[0] > $afcfg_attimagew || $groesse[1] > $afcfg_attimageh){
		              $a_errors[] ='<div class="yaforms-error">'.YAF_PICSIZEERROR.' <br />( '.YAF_MAX.' '.$afcfg_attimagew.' px X '.$afcfg_attimageh.' px )<br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'</div>';
                              $attfileerrchk[] = 'error';
                              $meldung2 .= '<div class="yaforms-error">'.YAF_NOTATTFILES.':<br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'</div>';
                           }
		        }
	             } else {
	                $a_errors[] ='<div class="yaforms-error">'.YAF_EMPTYFILE.'<br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'</div>';
                        $attfileerrchk[] = 'error';
                        $meldung2 .= '<div class="yaforms-error">'.YAF_NOTATTFILES.':<br />'.YAF_ATTACHFILE.': '.$_FILES['attfile']['name'][$g].'</div>';
                     }
                  }//if
          
                  if (!in_array('error', $attfileerrchk) && $_FILES['attfile']['name'][$g] != '' ){
                     $attachmentsucc = $_FILES['attfile']['name'][$g];
                     $attachmentsname = date('Y-m-d-H-i-s-').mosMakePassword('5').'-'.str_replace(' ','-',$_FILES['attfile']['name'][$g]);
                     $attachments[] = $artuplpfad.$attachmentsname;
                     $attachmentstodb[] = $attachmentsname;
                     move_uploaded_file($_FILES['attfile']['tmp_name'][$g],$artuplpfad.$attachmentsname);
                     $meldung .= '<font style="color:green">'.$attachmentsucc.': '.YAF_SUCCESS.'</font><br />';
                  }
               }//for - end attachment validation

            }// Upload and Attachment end

            //start of attachment's manditory checker
            if( in_array('error', $attfileerrchk) && $params->get( 'set_att_manditory' ) == '1' ){

               $a_errors[] = '<div class="yaforms-error"><br />'.YAF_ATTMANDITORY.'</div>';

            } else {

               if( $row->allowatt != '0' ){
                  if(@!$_FILES['attfile']) $meldung .= '<div class="yaforms-error"><br />'.YAF_SENTWOUTFILES.'</div>';
               }
               
               // Тело сообщения
               $subject = $mosConfig_sitename.': '.stripslashes($formtitle.' - '.$joomlauser);
               $crlf  = '<br />';
	       $hrline = '<hr>';
	       if ($row->html!='1'){
	          $crlf = "\n";
	          $hrline = "-----------------------------------------------";
	       }
               $email_copy_header = YAF_EMAILCOPYMAIL.$crlf.$crlf;
	       $body  = stripslashes($formtitle.' - '.$joomlauser.'('.$joomlausername.')').$crlf;
               $body .= $hrline.$crlf.$crlf;

               if($mail_data){
                  foreach($mail_data as $data_name => $data){
                     $body .= $data_name.': ';
                     if(is_array($data)){
                        $body .= $crlf;
                        $d2 = '';
	                foreach($data as $d){
		           $d2 .= $d;
	                }
	                $data = $d2;
	             }
                  $body .= $data.$crlf;
                  $body .= $hrline.$crlf;
                  }
               }
               $body .= YAF_JUSER.': '.$joomlauser.$crlf;
               $body .= YAF_JUSERNAME.': '.$joomlausername.$crlf;
               $body .= YAF_JUSERIP.': '.$joomlauserip.$crlf;
	       $body .= $hrline.$crlf;
               // Конец мэйлбоди

	       //Отправляем копию письма
	       $confirm = '';
	       $copyconfirm = '';

               if( $params->get( 'confirmation_email' ) != '' ){
                  $bodyc = $crlf.YAF_CONFIRMATIONEMAILTEXT.$crlf;
				  
				  
	          if (mosMail($config->config_mailfrom, $config->config_fromname, $params->get( 'confirmation_email' ), $subject, $bodyc, ($row->html=='1'), null, null, null)){
                     
				$copyconfirm = '';
	          
			  } else {
	            
				$confirm = '';
	          }
               }
               
               if ( $row->emailfield != '0' && mosGetParam( $_POST, 'email_copy', '' ) == '1'  && isset( $email_copy_to_sender ) ){
			   
					
	          if ( mosMail($config->config_mailfrom, $config->config_fromname, $email_copy_to_sender[0], $subject,
	 				$email_copy_header.$body, ($row->html=='1'), null, null,
	 				($attachments) ? $attachments:null)){
			  
                     $copyconfirm = YAF_EMAILCOPYSENDED;
					 
	          } else {
			  
	            	 $confirm = '<span class="message">'.YAF_MAILSENDERERRORCOPY.'</span>';
				 
                  }
	       }
		   
			//успешная или нет отправка формы
	       if (mosMail($mosConfig_mailfrom,$mosConfig_fromname,$row->email,$subject,$body,($row->html=='1'),($row->ccmail)?$row->ccmail:null,($row->bccmail)?$row->bccmail:null,($attachments)?$attachments:null))
		   {
	          $confirm = '<span class="message">'.$row->danktext.'<br />'.$copyconfirm.'</span></div>';
	       } else { 
	          $confirm = '<div class="yaforms-error">'.YAF_MAILSENDERERROR.'</div>';
	       }
        
	       //Удалить файл?
	       if ( $afcfg_attfilesave != '1' && isset($_FILES['attfile']['name'])){
                  for ( $g='0'; $g < $attfilescount; $g++ ) {
                     unlink ( $attachments[$g] );
                  }
               }
            }//end of attachment's manditory checker
            
         }//End of if(count($a_errors) == 0)


         if ($afcfg_dbsaveforms == '1' && count($a_errors) == 0 ){

            $itemname_todb = $itemname_todb.'ARTFJUSER;ARTFJUSERNAME;ARTFJUSERIP';
            $itemdata_todb = $itemdata_todb.$joomlauser.';'.$joomlausername.';'.$joomlauserip;
            if ($params->get( 'show_newsletter_system' ) != '0' && $params->get( 'show_newsletter_system' ) != '' && mosGetParam( $_POST, 'afnewsletter' ) == '1' ){
               $itemname_todb = $itemname_todb.';ARTFNLYES';
               $itemdata_todb = $itemdata_todb.';'.YAF_MULTI_YES;
            }
            if( is_array($attachmentstodb) ){
               $itemname_todb = $itemname_todb.';ARTFATTACHFILE';
               $itemdata_todb = $itemdata_todb.';'.implode('|', $attachmentstodb);
            }
            saveDBForms( $database, $option, $itemname_todb, $itemdata_todb, $formtitle, $formid );

         }
         if ($params->get( 'show_newsletter_system' ) != '0' && $params->get( 'show_newsletter_system' ) != '' && count($a_errors) == 0 && mosGetParam( $_POST, 'afnewsletter' ) == '1' ){
            $afgetuser = $joomlausername;
            if( $afgetuser == YAF_ANONYMOUS || $afgetuser == '' )$afgetuser = mosGetParam( $_POST, 'item_'.$items[0]->item_id );
            afMakeNewsletterBridgeToDB( $params->get( 'show_newsletter_system' ), ($my->id) ? $my->id : '0', $afgetuser, $email_copy_to_sender[0]  );
         }
         if ( $params->get( 'use_redirect_url' ) == '1' && $params->get( 'redirect_url' ) != '' && count($a_errors) == 0 ){
            mosRedirect( $params->get( 'redirect_url' ) );
         }

      } //end of do send

      if(isset($confirm)) {
         if ($meldung!='') {
	    $html .= $meldung;
         }
         if ($meldung2!='') {
	    $html .= $meldung2;
         }
         foreach($a_errors as $error){
            $html .= $error;
	 }
         $html .= $confirm;
      } else {

         if(count($a_errors) != 0){
            foreach($a_errors as $error){
               $html .= $error;
	    }
	 }

         $html .= '<div id="yaforms-text">'.$row->text.'</div>';
         
         $actionURL = sefRelToAbs( $alink.'&amp;formid='.$formid.'&amp;Itemid='.(int)$Itemid );

         if ( $row->customjscode != '' ){

            $htmlh = '<script type="text/javascript">';
               $customjscode = urldecode( $row->customjscode );
               if( get_magic_quotes_gpc()) {
                 $customjscode = stripcslashes($customjscode);
               }
               $customjscode = str_replace("&lt;","<",$customjscode);
	       $customjscode = str_replace("&gt;",">",$customjscode);
               $htmlh .= $customjscode;
            $htmlh .= '</script>';
            $mainframe->addCustomHeadTag( $htmlh );

         }
		
         afHitCounter( $formid );

         $html .= '<div id="yaforms-form">';

            if ($row->allowatt=='0'){
               $html .= '<form method="post" name="YaForms" id="YaForms" action="'.$actionURL.'">';
            } else {
               $html .= '<form method="post" name="YaForms" id="YaForms" enctype="multipart/form-data" action="'.$actionURL.'">
                         <input type="hidden" name="MAX_FILE_SIZE" value="'.($row->allowattfilesize * 1024).'" />';
            }
            $html .= '<input type="hidden" name="afversion" value="YaForms '.afVersionYar().'" />
                      <input type="hidden" name="formid" value="'.$row->id.'" />
                      <input type="hidden" name="do" value="send" />
                      <input type="hidden" name="formtitle" value="'.$row->titel.'" />
                      <input type="hidden" name="joomlauser" value="'.$my->name.'" />
                      <input type="hidden" name="joomlausername" value="'.$my->username.'" />
                      <input type="hidden" name="joomlauserip" value="'.$_SERVER['REMOTE_ADDR'].'" />';

            $artf_req  = '';
            $artf_datejs  = '';

            foreach($items as $item){

               $artf_req .= $item->required.',';
               $artf_datejs .= $item->type.',';

               $fieldname = afMakeFieldName( $item, $a_error_ids );
               $thefield = afMakeField( $item, $row->html, $row->afeditor );
               $asterisk = afCheckFieldReq( $item->required, $afcfg_asteriskimg );
               $html .= afPerformFields( $item->layout, $fieldname, $thefield, $asterisk );

            }
            
            $html .= afMakeNewsletterBridge( $params->get( 'show_newsletter_system' ) );
            
            $html .= afDoAttachmentsInForm ( $row->allowatt, $params->get( 'set_att_manditory' ), $afcfg_asteriskimg, $params->get( 'limit_attachs' ) );

            $html .= afEmailCopy( $row->emailfield );
			
			

            $html .= afDoCaptchasInForm( $row->seccode );
	    
            $html .= afShowRequirer( $artf_req, $afcfg_asteriskimg );

            $artf_datejs = substr($artf_datejs,0,-1);
	    $artf_datejs = explode(',', $artf_datejs);
            
			if (in_array('7', $artf_datejs)){
            
			mosCommonHTML::loadCalendar();
			    
            }

            $html .= afShowButtons( $params->get( 'show_reset_button' ) );

         $html .= '</form></div></div><div id="yaforms-forminfo">';
         $html .= afAuthor( $row, $params );
         $html .= afCreateDate( $row, $params );
         $html .= afModifiedDate( $row, $params );
         $html .= afBackBtn( $params );
		 $html .= afFooter();
         $html .= '</div>';
      
      }

      echo $html;
	  

   } //Конец функции ShowFrontYaForms


   function ShowFrontRootForms( $rows, $params, $option ){

      global $my, $database;

      $rootfronttitle = $params->get( 'rootfronttitle' );
      $fronttext = urldecode( $params->get( 'fronttext' ) );

      if( get_magic_quotes_gpc())$fronttext = stripcslashes($fronttext);

      echo '<div class="componentheading">
           '.$rootfronttitle.'
           </div>';
      echo '<div style="text-align:left;">
           '.$fronttext.'
           </div>';
      echo '<div style="font-size:12px;text-align:left;line-height:16px;"><ul>';

      if(isset($rows)){
         foreach ($rows as $row){
             if( $row->published == '1' && $row->access <= (int) $my->gid ) {
			 
			 $sql = "SELECT id FROM #__menu WHERE link='index.php?option=com_yaforms'";
				
				$database->setQuery($sql);
				$yaform_Itemid = $database->loadResult();

                $_Itemid = afGetItemid( $row->id );
                echo '<li><a href="'.sefRelToAbs( 'index.php?option='.$option.'&amp;formid='.$row->id
				.($yaform_Itemid ? '&amp;Itemid='
				.$yaform_Itemid : '&amp;Itemid=99999') ).'">'
				.$row->titel.'</a></li>';
				
             }
         }
      }
      echo '</ul></div>';
 
   }
  
}
?>
